/**
*   Author: 小 阮  
*       - Version 1.0.1
*       - 30/11/2017
*/
define([ "require", "exports" ], function(r, n) {
    "use strict";
    var t;
    (function(r) {
        function n(r) {
            return {
                size: function() {
                    return t(r);
                },
                trans: function() {
                    return u(r);
                },
                add: function(n) {
                    return i(r, n, e);
                },
                sub: function(n) {
                    return i(r, n, o);
                },
                mul: function(n) {
                    return i(r, n, f);
                },
                div: function(n) {
                    return i(r, n, a);
                },
                prod: function(n) {
                    return c(r, n);
                }
            };
        }
        r.func = n;
        function t(r) {
            var n = [];
            while (Array.isArray(r)) {
                n.push(r.length);
                r = r[0];
            }
            return n;
        }
        r.size = t;
        function u(r) {
            var n = t(r);
            var u = [];
            for (var i = 0; i < n[0]; i++) for (var e = 0; e < n[1]; e++) {
                if (Array.isArray(u[e])) u[e].push(r[i][e]); else u[e] = [ r[i][e] ];
            }
            return u;
        }
        r.trans = u;
        function i(r, n, t) {
            var u = [];
            var i = typeof n === "function" ? n() : n;
            var e = function(n) {
                var e = r[n];
                var o = i[n];
                u.push(e.map(function(r, n) {
                    return t(r, o[n]);
                }));
            };
            for (var o in r) {
                e(o);
            }
            return u;
        }
        r.operate = i;
        function e(r, n) {
            return r + n;
        }
        function o(r, n) {
            return r - n;
        }
        function f(r, n) {
            return r * n;
        }
        function a(r, n) {
            return r / n;
        }
        function c(r, n) {
            var u = r, i = typeof n === "function" ? n() : n;
            var e = t(u), o = t(i);
            var f = [];
            if (e[1] === o[0]) {
                for (var a = 0; a < e[0]; a++) {
                    f[a] = [];
                    for (var c = 0; c < o[1]; c++) {
                        for (var v = 0; v < e[1]; v++) {
                            if (!f[a][c]) f[a][c] = 0;
                            f[a][c] += u[a][v] * i[v][c];
                        }
                    }
                }
            }
            return f;
        }
        r.prod = c;
        function v(r) {
            return t(r).length;
        }
        r.dimensions = v;
        function s(r) {
            var n = [];
            for (var t = 0; t < r.length; t++) n.push(r[t].slice(0));
            return n;
        }
        r.clone = s;
    })(t = n.nnMatrix || (n.nnMatrix = {}));
});